<?php
/**
 *author:韩帅
 *createtime:2017/6/23 10:14
 *description:
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BfLines extends Model
{
    /**
     * 定义主键字段
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 定义表名，不含前缀
     *
     * @var string
     */
    protected $table      = 'wd_bf_lines';

    /**
     * 定义拒绝保存的字段
     *
     * @var array
     */
    protected $guarded    = ['id'];

    /**
     * 开启laravel默认的时间记录
     *
     * @var bool
     */
    public $timestamps = true;

    /**
     * 定义启用的状态
     */
    const STATUS_BEGIN = 1;

    /**
     * 定义禁用的状态
     */
    const STATUS_STOP  = 0;

    /**
     * 定义已删除的状态
     */
    const ISDELETE_YES  = 1;

    /**
     * 定义未删除的状态
     */
    const ISDELETE_NO   = 0;

    /**
     * 定义支付方式
     */
    private $pay_way    = [1 => '支付宝',2 => '微信支付',3 => '余额支付'];
    /**
     * 处理店铺队列列表
     */
    public  function translate($data)
    {
        $newArr                 = [];
        $newArr['total']        = $data['total'];
        $newArr['per_page']     = $data['per_page'];
        $newArr['current_page'] = $data['current_page'];
        $newArr['last_page']    = $data['last_page'];

        foreach ($data['data'] as &$v) {


            if (empty($v['money'])) {

                $v['money'] = 0.00;
            }else {

                $v['money'] = number_format($v['money'],2);
            }

//            $v['status'] = $this->status[intval($v['status'])];

            if (!empty(intval($v['pay_way']))) {
                $v['pay_way'] = $this->pay_way[intval($v['pay_way'])];
            }

            $newArr['data'][] = ['id'      => $v['id'] ,     'username'   => $v['username'],'money'      => $v['money'],
                                 'pay_way' => $v['pay_way'], 'order_id'   => $v['order_id'],'created_at' => $v['created_at'],
                                 'phone'   => $v['phone'],
                                    ];
        }

        return $newArr;
    }
}